package com.cloudsigns.factorymanager2.produce.activity.produce_team;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.IView.IUploadPhotoView;
import com.cloudsigns.factorymanager2.engineering.adapter.GridAdapter;
import com.cloudsigns.factorymanager2.engineering.adapter.PopWindowAdapter;
import com.cloudsigns.factorymanager2.engineering.bean.DialogItemBean;
import com.cloudsigns.factorymanager2.engineering.customview.BottomListDialog;
import com.cloudsigns.factorymanager2.engineering.customview.SpinerPopWindow;
import com.cloudsigns.factorymanager2.engineering.presenter.UploadPhotoPresenter;
import com.cloudsigns.factorymanager2.engineering.utils.PhotoUtil;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartBean;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartOrderBean;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartScheduleBean;
import com.cloudsigns.factorymanager2.produce.iview.produce_team.IDailyFeedbackView;
import com.cloudsigns.factorymanager2.produce.iview.produce_team.IPlanUnusualDailyFeedbackView;
import com.cloudsigns.factorymanager2.produce.iview.produce_team.IProduceUnusualDailyFeedbackView;
import com.cloudsigns.factorymanager2.produce.presenter.produce_team.DailyFeedbackPresenter;
import com.cloudsigns.factorymanager2.produce.presenter.produce_team.PlanUnusualDailyFeedbackPresenter;
import com.cloudsigns.factorymanager2.produce.presenter.produce_team.ProduceUnusualDailyFeedbackPresenter;
import com.cloudsigns.factorymanager2.produce.utils.ProduceForTeamEvent;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.FileUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import de.greenrobot.event.EventBus;

public class ProduceTeamDailyFeedbackActivity extends BaseActivity implements IUploadPhotoView, IDailyFeedbackView, IPlanUnusualDailyFeedbackView, IProduceUnusualDailyFeedbackView, BottomListDialog.OnItemDialogClick, AdapterView.OnItemClickListener {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private RadioGroup rg_feedback_type;
    private RadioButton rb_feedback_normal, rb_feedback_abnormal;
    private LinearLayout ll_normal_feedback;
    private LinearLayout ll_cb_unusual_feedback;
    private RadioGroup rg_unusual_feedback;
    private RadioButton rb_unusual_plan, rb_unusual_machin;
    private LinearLayout ll_plan_feedback, ll_machin_unusual;

    private TextView tv_plan_output;
    private EditText edt_today_output, edt_feedback_content;
    private ImageView img_feedback_content;
    private GridView normalGridView;

    private TextView tv_plan_fb_plan_output;
    private EditText edt_plan_fb_today_output, edt_plan_fb_unfinished_reason;
    private ImageView img_plan_fb_unfinished_reason;
    private EditText edt_plan_fb_advice;


    private EditText edt_machin_fb_unusual_reason;
    private ImageView img_machin_fb_unusual_reason;
    private EditText edt_machin_fb_affect_day_num;
    private ImageView img_machin_fb_unusual_day_num;
    private EditText edt_machin_fb_affect_advice;
    private GridView produceGridView;

    private Button btn_submit;

    private GridAdapter normalGridAdapter;
    private List<String> normalPathList = new ArrayList<>();
    private List<String> normalServerUrlList = new ArrayList<>();
    private String normalFilePath;

    private GridAdapter produceGridAdapter;
    private List<String> producePathList = new ArrayList<>();
    private List<String> produceServerUrlList = new ArrayList<>();
    private String produceFilePath;


    private SpinerPopWindow<String> feedbackContentPopWindow, unfinishReasonPopWindow, unusualReasonPopWindow, affectDaysPopWindow;
    private PopWindowAdapter feedbackContentPwAdapter, unfinishReasonPwAdapter, unusualReasonPwAdapter, affectDaysPwAdapter;

    private List<String> feedbackContentStrLs = new ArrayList<String>();
    private List<String> unfinishReasonStrLs = new ArrayList<String>();
    private List<String> unusualReasonStrLs = new ArrayList<String>();
    private List<String> affectDaysStrLs = new ArrayList<String>();

    private int produce_pop;
    private int UNUSUAL_REASON_POP = 1;
    private int AFFECT_DAYS_POP = 2;

    private WorkPartBean workPartBean;
    private WorkPartOrderBean workPartOrderBean;

    private final int NORMAL_FEEDBACK = 1;
    private final int UNSUAL_FEEDBACK = 2;
    private int feedBackType = NORMAL_FEEDBACK;

    private final int PLAN_UNUSUAL = 1;
    private final int PRODUCE_UNUSUAL = 2;
    private int unusualType = PLAN_UNUSUAL;

    private UploadPhotoPresenter uploadPhotoPresenter;
    private DailyFeedbackPresenter dailyFeedbackPresenter;
    private PlanUnusualDailyFeedbackPresenter planUnusualDailyFeedbackPresenter;
    private ProduceUnusualDailyFeedbackPresenter produceUnusualDailyFeedbackPresenter;


    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_produce_team_daily_feedback);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        rg_feedback_type = findViewById(R.id.rg_feedback_type);
        rb_feedback_normal = findViewById(R.id.rb_feedback_normal);
        rb_feedback_abnormal = findViewById(R.id.rb_feedback_abnormal);
        ll_normal_feedback = findViewById(R.id.ll_normal_feedback);
        ll_cb_unusual_feedback = findViewById(R.id.ll_cb_unusual_feedback);
        ll_plan_feedback = findViewById(R.id.ll_plan_feedback);
        rg_unusual_feedback = findViewById(R.id.rg_unusual_feedback);
        rb_unusual_plan = findViewById(R.id.rb_unusual_plan);
        rb_unusual_machin = findViewById(R.id.rb_unusual_machin);
        ll_machin_unusual = findViewById(R.id.ll_machin_unusual);
        tv_plan_output = findViewById(R.id.tv_plan_output);
        edt_today_output = findViewById(R.id.edt_today_output);
        edt_feedback_content = findViewById(R.id.edt_feedback_content);
        img_feedback_content = findViewById(R.id.img_feedback_content);
        normalGridView = findViewById(R.id.gridView_normal_feedback);
        tv_plan_fb_plan_output = findViewById(R.id.tv_plan_fb_plan_output);
        edt_plan_fb_today_output = findViewById(R.id.edt_plan_fb_today_output);
        edt_plan_fb_unfinished_reason = findViewById(R.id.edt_plan_fb_unfinished_reason);
        img_plan_fb_unfinished_reason = findViewById(R.id.img_plan_fb_unfinished_reason);
        edt_plan_fb_advice = findViewById(R.id.edt_plan_fb_advice);
        edt_machin_fb_unusual_reason = findViewById(R.id.edt_machin_fb_unusual_reason);
        img_machin_fb_unusual_reason = findViewById(R.id.img_machin_fb_unusual_reason);
        edt_machin_fb_affect_day_num = findViewById(R.id.edt_machin_fb_affect_day_num);
        img_machin_fb_unusual_day_num = findViewById(R.id.img_machin_fb_unusual_day_num);
        edt_machin_fb_affect_advice = findViewById(R.id.edt_machin_fb_affect_advice);
        produceGridView = findViewById(R.id.gridView_produce);
        btn_submit = findViewById(R.id.btn_submit);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText(getResources().getString(R.string.daily_feed_back));

        Intent intent = getIntent();
        if (null != intent) {
            workPartBean = (WorkPartBean) intent.getSerializableExtra(ConstantUtil.KEY_1);
            workPartOrderBean = (WorkPartOrderBean) intent.getSerializableExtra(ConstantUtil.KEY_2);
        }

        rb_feedback_normal.setChecked(true);


        WorkPartScheduleBean sbean = workPartBean.getScheduleBeanByTime(System.currentTimeMillis());
        int count = 0;
        if (sbean != null) {
            count = sbean.getAmount();
        }
        tv_plan_output.setText(String.valueOf(count));
        tv_plan_fb_plan_output.setText(String.valueOf(count));


        // 影响天数
        affectDaysPopWindow = new SpinerPopWindow<String>(this, this);
        affectDaysPwAdapter = new PopWindowAdapter(this, TAG);
        affectDaysStrLs.add("0");
        affectDaysStrLs.add("1");
        affectDaysStrLs.add("2");
        affectDaysStrLs.add("3");
        affectDaysStrLs.add("4");
        affectDaysStrLs.add("5");
        affectDaysStrLs.add("6");
        affectDaysStrLs.add("7");
        affectDaysPwAdapter.setData(affectDaysStrLs);
        affectDaysPopWindow.setAdapter(affectDaysPwAdapter);


        uploadPhotoPresenter = new UploadPhotoPresenter(this);
        dailyFeedbackPresenter = new DailyFeedbackPresenter(this);
        planUnusualDailyFeedbackPresenter = new PlanUnusualDailyFeedbackPresenter(this);
        produceUnusualDailyFeedbackPresenter = new ProduceUnusualDailyFeedbackPresenter(this);
    }


    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);
        img_feedback_content.setOnClickListener(this);
        img_plan_fb_unfinished_reason.setOnClickListener(this);
        img_machin_fb_unusual_reason.setOnClickListener(this);
        img_machin_fb_unusual_day_num.setOnClickListener(this);
        rb_unusual_plan.setOnClickListener(this);
        rb_unusual_machin.setOnClickListener(this);
        btn_submit.setOnClickListener(this);

        rg_feedback_type.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int id) {
                if (id == R.id.rb_feedback_normal) {
                    feedBackType = NORMAL_FEEDBACK;
                    updateUIType();

                } else if (id == R.id.rb_feedback_abnormal) {
                    feedBackType = UNSUAL_FEEDBACK;
                    updateUIType();
                }
            }
        });

        rg_unusual_feedback.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int id) {
                if (id == R.id.rb_unusual_plan) {
                    unusualType = PLAN_UNUSUAL;
                    updateUIAbnormal();

                } else if (id == R.id.rb_unusual_machin) {
                    unusualType = PRODUCE_UNUSUAL;
                    updateUIAbnormal();
                }
            }
        });


        normalPathList.add("paizhao");
        normalGridView.setNumColumns(3);
        normalGridAdapter = new GridAdapter(this);
        normalGridAdapter.setData(normalPathList);
        normalGridView.setAdapter(normalGridAdapter);

        normalGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long l) {

                String imgs = (String) parent.getItemAtPosition(position);
                if ("paizhao".equals(imgs)) {
                    showListDialog();
                } else {

                }
            }
        });


        producePathList.add("paizhao");
        produceGridView.setNumColumns(3);
        produceGridAdapter = new GridAdapter(this);
        produceGridAdapter.setData(producePathList);
        produceGridView.setAdapter(produceGridAdapter);

        produceGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long l) {

                String imgs = (String) parent.getItemAtPosition(position);
                if ("paizhao".equals(imgs)) {
                    showListDialog();
                } else {

                }
            }
        });
    }

    private void showListDialog() {
        DialogItemBean[] items = new DialogItemBean[]{
                new DialogItemBean(R.string.camera,
                        R.layout.dialog_list_item_normal),
                new DialogItemBean(R.string.gallary,
                        R.layout.dialog_list_item_normal),
                new DialogItemBean(R.string.cancel,
                        R.layout.dialog_list_item_normal)};
        BottomListDialog dialog = new BottomListDialog(this, Arrays.asList(items));
        dialog.setItemClick(this);
        dialog.show();
    }


    // 反馈类型
    private void updateUIType() {
        if (feedBackType == NORMAL_FEEDBACK) {
            ll_normal_feedback.setVisibility(View.VISIBLE);
            ll_cb_unusual_feedback.setVisibility(View.GONE);
            ll_plan_feedback.setVisibility(View.GONE);
            ll_machin_unusual.setVisibility(View.GONE);

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            rb_unusual_plan.setChecked(true);
            ll_normal_feedback.setVisibility(View.GONE);
            ll_cb_unusual_feedback.setVisibility(View.VISIBLE);
            ll_plan_feedback.setVisibility(View.VISIBLE);
        }
    }

    // 异常反馈
    private void updateUIAbnormal() {
        if (unusualType == PLAN_UNUSUAL) {
            ll_plan_feedback.setVisibility(View.VISIBLE);
            ll_machin_unusual.setVisibility(View.GONE);
        } else if (unusualType == PRODUCE_UNUSUAL) {
            ll_plan_feedback.setVisibility(View.GONE);
            ll_machin_unusual.setVisibility(View.VISIBLE);
        }
    }

    // 提交反馈
    private void submitFeedBack() {
        if (feedBackType == NORMAL_FEEDBACK) {
            if (TextUtils.isEmpty(edt_today_output.getText().toString())) {
                showToast(getResources().getString(R.string.input_today_output));
                return;
            } else if (TextUtils.isEmpty(edt_feedback_content.getText().toString())) {
                showToast(getResources().getString(R.string.feedback_content_no_empty));
                return;
            } else {
                dailyFeedbackPresenter.dailyFeedback();
            }
        } else if (feedBackType == UNSUAL_FEEDBACK) {
            switch (unusualType) {
                // 计划异常
                case PLAN_UNUSUAL:
                    if (TextUtils.isEmpty(edt_plan_fb_today_output.getText().toString())) {
                        showToast(getResources().getString(R.string.input_today_output));
                        return;
                    } else if (TextUtils.isEmpty(edt_plan_fb_unfinished_reason.getText().toString())) {
                        showToast(getResources().getString(R.string.unfinish_reason_no_empty));
                        return;
                    } else if (TextUtils.isEmpty(edt_plan_fb_advice.getText().toString())) {
                        showToast(getResources().getString(R.string.input_advice));
                        return;
                    } else {
                        planUnusualDailyFeedbackPresenter.planUnusualDailyFeedback();
                    }
                    break;
                // 加工异常
                case PRODUCE_UNUSUAL:
                    if (TextUtils.isEmpty(edt_machin_fb_unusual_reason.getText().toString())) {
                        showToast(getResources().getString(R.string.unusual_reason_no_empty));
                        return;
                    } else if (TextUtils.isEmpty(edt_machin_fb_affect_day_num.getText().toString())) {
                        showToast(getResources().getString(R.string.days_no_empty));
                        return;
                    } else if (TextUtils.isEmpty(edt_machin_fb_affect_advice.getText().toString())) {
                        showToast(getResources().getString(R.string.input_advice));
                        return;
                    } else {
                        produceUnusualDailyFeedbackPresenter.produceUnusualDailyFeedback();
                    }
                    break;
            }
        }
    }

    // 影响天数
    private void showAffectDaysPopWindow() {
        affectDaysPopWindow.setWidth(edt_machin_fb_affect_day_num.getWidth() / 2);
        affectDaysPopWindow.showAsDropDown(edt_machin_fb_affect_day_num);
    }

    @Override
    public void widgetClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            // 反馈内容
            case R.id.img_feedback_content:
                break;
            // 未完原因
            case R.id.img_plan_fb_unfinished_reason:
                break;
            // 异常原因
            case R.id.img_machin_fb_unusual_reason:
                break;
            // 影响天数
            case R.id.img_machin_fb_unusual_day_num:
                produce_pop = AFFECT_DAYS_POP;
                showAffectDaysPopWindow();
                break;
            // 提交
            case R.id.btn_submit:
                submitFeedBack();
                break;
        }
    }

    @Override
    public void onItemDialogClick(DialogItemBean item) {

        switch (item.getmTextId()) {
            case R.string.camera: {
                PhotoUtil.startCamear(ProduceTeamDailyFeedbackActivity.this, null);
                break;
            }
            case R.string.gallary: {
                PhotoUtil.startGallery(ProduceTeamDailyFeedbackActivity.this, null);
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        if (feedBackType == NORMAL_FEEDBACK) {
            edt_feedback_content.setText(feedbackContentStrLs.get(i));
            edt_feedback_content.setSelection(feedbackContentStrLs.get(i).length());
        }

        if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PLAN_UNUSUAL) {
                edt_plan_fb_unfinished_reason.setText(unfinishReasonStrLs.get(i));
            }

            if (unusualType == PRODUCE_UNUSUAL) {
                if (produce_pop == UNUSUAL_REASON_POP)
                    edt_machin_fb_unusual_reason.setText(unusualReasonStrLs.get(i));
                else if (produce_pop == AFFECT_DAYS_POP)
                    edt_machin_fb_affect_day_num.setText(affectDaysStrLs.get(i));
            }

            if (null != feedbackContentPopWindow)
                feedbackContentPopWindow.dismiss();
            if (null != unfinishReasonPopWindow)
                unfinishReasonPopWindow.dismiss();
            if (null != unusualReasonPopWindow)
                unusualReasonPopWindow.dismiss();
            if (null != affectDaysPopWindow)
                affectDaysPopWindow.dismiss();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {

            case PhotoUtil.CAMERA:
                if (resultCode == RESULT_OK) {

                    if (feedBackType == NORMAL_FEEDBACK) {
                        File normalFile = new File(PhotoUtil.filePath);
                        if (!normalFile.exists()) {
                            normalFile = new File(PhotoUtil.filePath);
                        }

                        normalFilePath = PhotoUtil.CAMERA_SEVER + normalFile.getName();
                        normalFilePath = PhotoUtil.imageCompressionAndSave(normalFile.getAbsolutePath(), normalFilePath);

                        if (normalPathList.contains("paizhao")) {
                            normalPathList.remove("paizhao");
                        }
                        if (normalPathList.size() < 3) {
                            normalPathList.add(normalFilePath);
                            if (normalPathList.size() < 3)
                                normalPathList.add("paizhao");

                            normalGridAdapter.setData(normalPathList);
                            normalGridAdapter.notifyDataSetChanged();
                        }

                    } else if (feedBackType == UNSUAL_FEEDBACK) {
                        switch (unusualType) {
                            case PRODUCE_UNUSUAL:
                                File produceFile = new File(PhotoUtil.filePath);
                                if (!produceFile.exists()) {
                                    produceFile = new File(PhotoUtil.filePath);
                                }

                                produceFilePath = PhotoUtil.CAMERA_SEVER + produceFile.getName();
                                produceFilePath = PhotoUtil.imageCompressionAndSave(produceFile.getAbsolutePath(), produceFilePath);

                                if (producePathList.contains("paizhao")) {
                                    producePathList.remove("paizhao");
                                }
                                if (producePathList.size() < 3) {
                                    producePathList.add(produceFilePath);
                                    if (producePathList.size() < 3)
                                        producePathList.add("paizhao");

                                    produceGridAdapter.setData(producePathList);
                                    produceGridAdapter.notifyDataSetChanged();
                                }
                                break;
                        }
                    }
                    uploadPhotoPresenter.uploadPhtoto();
                }


                break;
            case PhotoUtil.GALLERY:
                if (resultCode == RESULT_OK) {

                    if (feedBackType == NORMAL_FEEDBACK) {
                        String normalPath = FileUtil.getRealPathFromURI(this, Uri.parse(data.getData() + ""));

                        if (normalPathList.contains("paizhao")) {
                            normalPathList.remove("paizhao");
                        }

                        if (normalPathList.size() < 3) {

                            normalPathList.add(normalPath);
                            if (normalPathList.size() < 3)
                                normalPathList.add("paizhao");
                            normalGridAdapter.setData(normalPathList);
                            normalGridAdapter.notifyDataSetChanged();
                        }
                        File f = new File(normalPath);
                        normalFilePath = PhotoUtil.CAMERA_SEVER + f.getName();
                        normalFilePath = PhotoUtil.imageCompressionAndSave(normalPath, normalFilePath);

                    } else if (feedBackType == UNSUAL_FEEDBACK) {
                        switch (unusualType) {
                            case PRODUCE_UNUSUAL:
                                String producePath = FileUtil.getRealPathFromURI(this, Uri.parse(data.getData() + ""));

                                if (producePathList.contains("paizhao")) {
                                    producePathList.remove("paizhao");
                                }

                                if (producePathList.size() < 3) {

                                    producePathList.add(producePath);
                                    if (producePathList.size() < 3)
                                        producePathList.add("paizhao");
                                    produceGridAdapter.setData(producePathList);
                                    produceGridAdapter.notifyDataSetChanged();
                                }
                                File f = new File(producePath);
                                produceFilePath = PhotoUtil.CAMERA_SEVER + f.getName();
                                produceFilePath = PhotoUtil.imageCompressionAndSave(producePath, produceFilePath);
                                break;
                        }
                    }
                    uploadPhotoPresenter.uploadPhtoto();
                }
                break;

        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public String getAdvice() {
        if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PLAN_UNUSUAL) {
                return edt_plan_fb_advice.getText().toString().trim();

            } else if (unusualType == PRODUCE_UNUSUAL) {
                return edt_machin_fb_affect_advice.getText().toString().trim();
            }
        }
        return "";
    }

    @Override
    public int getDays() {
        if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PRODUCE_UNUSUAL) {
                return Integer.parseInt(edt_machin_fb_affect_day_num.getText().toString().trim());
            }
        }
        return 0;
    }

    @Override
    public int getAmount() {
        if (feedBackType == NORMAL_FEEDBACK) {
            return Integer.parseInt(edt_today_output.getText().toString().trim());

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PLAN_UNUSUAL) {
                return Integer.parseInt(edt_plan_fb_today_output.getText().toString().trim());
            }
        }
        return 0;
    }

    @Override
    public String getContent() {
        if (feedBackType == NORMAL_FEEDBACK) {
            return edt_feedback_content.getText().toString();
        }
        return "";
    }

    @Override
    public String getReason() {
        if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PLAN_UNUSUAL) {
                return edt_plan_fb_unfinished_reason.getText().toString().trim();

            } else if (unusualType == PRODUCE_UNUSUAL) {
                return edt_machin_fb_unusual_reason.getText().toString().trim();
            }
        }
        return "";
    }

    @Override
    public List<String> getImgUrlList() {
        if (feedBackType == NORMAL_FEEDBACK) {
            return normalServerUrlList;

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PRODUCE_UNUSUAL) {
                return produceServerUrlList;
            }
        }
        return null;
    }

    @Override
    public String getOrderId() {
        return workPartBean.getOrderId();
    }

    @Override
    public String getProductId() {
        return workPartBean.getProductId();
    }

    @Override
    public String getWorkPartId() {
        return workPartBean.getWorkPartId();
    }

    @Override
    public String getWorkPartOrderId() {
        return workPartOrderBean.getWorkPartOrderId();
    }

    @Override
    public void produceUnusualDailyFeedbackSuccessed() {
        showToast(getResources().getString(R.string.produce_feedback_success));
        EventBus.getDefault().post(new ProduceForTeamEvent());
        finish();
    }

    @Override
    public void produceUnusualDailyFeedback(final String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(desc);
            }
        });
    }

    @Override
    public void planUnusualDailyFeedbackSuccessed() {
        showToast(getResources().getString(R.string.plan_feedback_success));
        EventBus.getDefault().post(new ProduceForTeamEvent());
        finish();
    }

    @Override
    public void planUnusualDailyFeedback(final String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(desc);
            }
        });
    }

    @Override
    public void dailyFeedbackSuccessed() {
        showToast(getResources().getString(R.string.normal_feedback_success));
        EventBus.getDefault().post(new ProduceForTeamEvent());
        finish();
    }

    @Override
    public void dailyFeedbackFailed(final String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(desc);
            }
        });
    }

    @Override
    public String getFilePath() {
        if (feedBackType == NORMAL_FEEDBACK) {
            return normalFilePath;

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            if (unusualType == PRODUCE_UNUSUAL) {
                return produceFilePath;
            }
        }
        return null;
    }

    @Override
    public void upLoadPhotoSuccessed(String uri) {
        if (feedBackType == NORMAL_FEEDBACK) {
            normalServerUrlList.add(uri);

        } else if (feedBackType == UNSUAL_FEEDBACK) {
            switch (unusualType) {
                case PRODUCE_UNUSUAL:
                    produceServerUrlList.add(uri);
                    break;
            }
        }
    }

    @Override
    public void upLoadPhotoFailed(final String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(desc);
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }


    @Override
    protected void onDestroy() {
        if (null != feedbackContentPopWindow) {
            feedbackContentPopWindow.dismiss();
            feedbackContentPopWindow = null;
        }
        if (null != unfinishReasonPopWindow) {
            unfinishReasonPopWindow.dismiss();
            unfinishReasonPopWindow = null;
        }
        if (null != affectDaysPopWindow) {
            affectDaysPopWindow.dismiss();
            affectDaysPopWindow = null;
        }
        super.onDestroy();
    }
}
